/**
 * 初始化广告详情对话框
 */
var WzAdvInfoDlg = {
    wzAdvInfoData : {}
};

/**
 * 清除数据
 */
WzAdvInfoDlg.clearData = function() {
    this.wzAdvInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
WzAdvInfoDlg.set = function(key, val) {
    this.wzAdvInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
WzAdvInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
WzAdvInfoDlg.close = function() {
    parent.layer.close(window.parent.WzAdv.layerIndex);
}

/**
 * 收集数据
 */
WzAdvInfoDlg.collectData = function() {
    this
        .set('advId')
        .set('title')
        .set('coverUrl')
        .set('publishingType')
        .set('type')
        .set('status')
        .set('pushNumber')
        .set('totalReward')
        .set('surplusReward')
        .set('rewardType')
        .set('rewardAverage')
        .set('rewardRange')
        .set('beginTime')
        .set('endTime')
        .set('screenGender')
        .set('screenMinAge')
        .set('screenMaxAge')
        .set('screenCity')
        .set('hasDetail')
        .set('subtype')
        .set('screenRange');
}

/**
 * 提交添加
 */
WzAdvInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/wzAdv/add", function(data){
        Feng.success("添加成功!");
        window.parent.WzAdv.table.refresh();
        WzAdvInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.wzAdvInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
WzAdvInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/wzAdv/update", function(data){
        Feng.success("修改成功!");
        window.parent.WzAdv.table.refresh();
        WzAdvInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.wzAdvInfoData);
    ajax.start();
}

$(function() {

    // 初始化头像上传
    var avatarUp = new $WebUpload("avatar1");
    avatarUp.setUploadBarId("progressBar");
    avatarUp.init();

});
